Skip to content

feat: add Polar support for Convex-backed Better Auth projects with CLI integration#110

Merged
Marve10s merged 21 commits intoMarve10s:mainfrom
Alisha-21-cloud:convex-polar-support
Apr 2, 2026
Merged

feat: add Polar support for Convex-backed Better Auth projects with CLI integration#110
Marve10s merged 21 commits intoMarve10s:mainfrom
Alisha-21-cloud:convex-polar-support

Conversation

@Alisha-21-cloud
Copy link
Copy Markdown

This pull request adds first-class support for integrating Polar Payments with Convex backends when using Better Auth. It updates the CLI, template generator, and project templates to scaffold all necessary code, dependencies, environment variables, and documentation for this combination. The changes ensure that projects using Convex, Better Auth, and Polar Payments are correctly scaffolded and tested out-of-the-box.

Key changes include:

Support for Convex + Better Auth + Polar Payments:

  • Enabled Polar Payments as a compatible option for Convex backends using Better Auth, updating compatibility checks in the CLI prompt logic.
  • Added a comprehensive test that scaffolds a project with Convex, Better Auth, and Polar Payments, verifying that all expected files, dependencies, and environment variables are generated.

Template and Code Generation:

  • Updated template generator logic to process and inject Polar Payments templates for Convex backends, including both backend and web React templates. [1] [2] [3]
  • Enhanced dashboard page templates for React (Next.js, Vite, Tanstack Router) to include Polar Payments UI components and subscription logic when Polar is enabled. [1] [2] [3]

Dependencies and Environment Variables:

  • Automatically adds required Polar-related dependencies (@convex-dev/polar, @polar-sh/sdk, @polar-sh/checkout) to backend and web package.json files for Convex projects. [1] [2] [3]
  • Generates all necessary Polar Payments environment variables and documentation in packages/backend/.env.local for Convex projects, including comments and setup instructions. [1] [2] [3] [4] [5]

Post-Installation Instructions:

  • Updated post-installation instructions to include Polar Payments setup steps for Convex backends, with package manager awareness. [1] [2]

These changes make it seamless to scaffold and use Polar Payments with Convex and Better Auth, providing a robust developer experience for this stack.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 31, 2026

@Alisha-21-cloud is attempting to deploy a commit to the Ibrahim's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Marve10s
Copy link
Copy Markdown
Owner

Hey! Thank you for the PR! Will take a closer look soon

@Alisha-21-cloud
Copy link
Copy Markdown
Author

fix: resolve auth test failure for Convex Better Auth with Polar payments

The test was failing due to two issues:

  1. Undefined fs and path references - The test using fs.readFile() and
    path.join() but only imported readFile() and join(). Fixed by using
    the correctly imported functions throughout.

  2. Outdated env file assertion - The test expected "# POLAR_PRODUCT_ID_PRO="
    but the CLI now generates "# npx convex env set POLAR_PRODUCT_ID_PRO=...".
    Updated the assertion to match the current generated format.

Result: All 99 auth tests now pass ✓

@Marve10s
Copy link
Copy Markdown
Owner

Marve10s commented Apr 1, 2026

PR Review — Verified Issues

I scaffolded projects from this branch to verify the issues below. Each one was confirmed against actual generated output.


1. createFileRoute removed — breaks tanstack-router/start routing (Critical)

The PR replaces the tanstack-router and tanstack-start dashboard templates entirely, removing:

import { createFileRoute } from "@tanstack/react-router";

export const Route = createFileRoute("/dashboard")({
  component: RouteComponent,
});

The generated dashboard.tsx uses export default function Dashboard() instead, which does not register as a route in TanStack Router's file-based routing system. Other routes in the same generated project (e.g. index.tsx) correctly use createFileRoute.

This breaks ALL Convex + Better Auth + tanstack-router/start projects, even with --payments none, because the template replacement overwrites the entire file regardless of the payments flag.


2. polar.ts.hbs contains embedded template metadata (Critical)

The generated packages/backend/convex/polar.ts has literal garbage at lines 61–66:

`],
  ["payments/polar/convex/web/react/tanstack-start/src/functions/get-payment.ts.hbs", `import { createServerFn } from "@tanstack/react-start";

export const getPayment = createServerFn({ method: "GET" }).handler(async () => {
  return null;
});

This is template registry metadata that leaked into the .hbs file. The get-payment.ts.hbs content was accidentally concatenated into polar.ts.hbs. The generated backend file is invalid JavaScript and will not parse.


3. buttonVariants import from nonexistent package (Medium)

The dashboard template imports:

import { buttonVariants } from "@{{projectName}}/ui/components/button";

When scaffolding with --ui-library none, there is no packages/ui workspace package. The buttonVariants export exists at apps/web/src/components/ui/button.tsx (local path), but the workspace package import will fail at build time. This should either be conditional on the UI library or use a relative/alias import.


4. Missing spaces after commas (Minor)

// post-installation.ts
getPolarInstructions(backend,packageManager)

// env-vars.ts
buildConvexCommentBlocks(frontend, auth,payments, examples)
buildConvexBackendVars(frontend, auth,payments, examples)

5. Stub get-payment.ts.hbs returns null (Minor)

payments/polar/convex/web/react/tanstack-start/src/functions/get-payment.ts.hbs returns null with no actual logic. The non-convex tanstack-start version has a working implementation using authClient.customer.state(). Either implement this for Convex or remove the file.


What looks good

  • Compatibility and prompt changes (removing the Convex exclusion) are clean
  • Dependency wiring (@convex-dev/polar, @polar-sh/sdk, @polar-sh/checkout) is correct with proper version pinning
  • Env var generation and comment blocks for .env.local are well structured
  • Post-install instructions with Convex-specific convex env set commands are helpful
  • convex.config.ts and http.ts Handlebars conditionals are correct
  • The test is comprehensive and checks the right things
  • The polar.ts business logic (lines 1–60, ignoring the corruption) is solid

Summary

The plumbing (deps, env vars, compatibility, post-install) is solid work. The critical issues are in the template files — they need to preserve createFileRoute for tanstack-router/start, the polar.ts.hbs corruption needs to be fixed, and the buttonVariants import path needs to account for projects without a UI library package.

@Marve10s
Copy link
Copy Markdown
Owner

Marve10s commented Apr 1, 2026

@Alisha-21-cloud There are lot of issues, I'm always okay with using AI to code but please review and verify your changes, if you'd like to fix all issues above - I can re-review the PR again

@Alisha-21-cloud
Copy link
Copy Markdown
Author

Thanks for the detailed review 🙌
I’ll fix these issues ASAP and push an updated commit for your review.

@Alisha-21-cloud
Copy link
Copy Markdown
Author

Fixes Completed ✅

I’ve addressed all the reported issues. Please review the changes below:

Issue Severity Type Status
TanStack Router routing broken Critical Architecture ✅ Fixed
Polar.ts template metadata leak Critical Data Integrity ✅ Fixed
buttonVariants missing import Medium Build Error ✅ Fixed
Missing spaces after commas Minor Code Style ✅ Fixed
Stub get-payment.ts implementation Minor Documentation ✅ Fixed

All fixes have been pushed. Please take a look when you get a chance

@Marve10s
Copy link
Copy Markdown
Owner

Marve10s commented Apr 2, 2026

Will try to take a look today. Thank you

Marve10s and others added 7 commits April 2, 2026 15:08
- Revert unrelated elasticsearch feature (schema, deps, env vars, templates,
  tests, web constants/icons/links) — should be a separate PR
- Revert ignoreDeprecations additions to 13 tsconfig files
- Revert TinaCMS env var and README indentation changes
- Revert unrelated svelte/next template tweaks
- Remove dead useQuery/api imports from convex get-payment.ts.hbs
- Add missing trailing newlines to 5 template files
- Update snapshots to match reverted templates
Reverts unrelated elasticsearch removals that were accidentally included
in this PR. Elasticsearch was added in a separate merged PR and should
not be removed here.
@github-actions github-actions bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. vouch:unvouched PR author is not yet trusted in the VOUCHED list. and removed vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. labels Apr 2, 2026
@github-actions github-actions bot added the size:L 100-499 effective changed lines (test files excluded in mixed PRs). label Apr 2, 2026
@Marve10s Marve10s merged commit ecbd44f into Marve10s:main Apr 2, 2026
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 effective changed lines (test files excluded in mixed PRs). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants